package com.acme.bankapp.domain.bank;

import com.acme.bankapp.exception.bank.ClientExistsException;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Class representing bank
 */
public class Bank {
    private List<Client> clients;

    /**
     * Instantiate bank with no clients
     */
    public Bank(){
        this.clients = new ArrayList<Client>();
    }

    /**
     * Create bank with preset clients
     * @param clients Initial clients
     */
    public Bank(List<Client> clients){
        this.clients = clients;
    }

    /**
     * @param client Client to add
     * @return Just added client
     */
    public boolean addClient(Client client) throws  ClientExistsException{
        for(Client existingClient:clients){
            if(existingClient.getName()==client.getName()){
                throw new ClientExistsException(String.format("Client with name %s already exists!",client.getName()));
            }

        }
        return clients.add(client);
    }

    /**
     * Removes client from Bank
     * @param client Client remove
     * @return removed client
     */
    public boolean removeClient(Client client){
        return  clients.remove(client);
    }

    /**
     * Returns all clients
     * @return All bank clients
     */
    public Collection<Client> getAllClients(){
        return clients;
    }

}
